from rest_framework.generics import ListAPIView, ListCreateAPIView

from meiduo_admin.serializers.user import UserSerializer, PageNum
from users.models import User


class UserView(ListCreateAPIView):
    # 指定使用的序列化器
    serializer_class = UserSerializer
    # queryset = User.objects.all()
    pagination_class = PageNum

    def get_queryset(self):
        keyword = self.request.query_params.get('keyword')
        if keyword == '' or keyword is None:
            return User.objects.all()
        else:
            return User.objects.filter(username=keyword)